unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, RzPanel, RzSplit, fs_synmemo, fs_iinterpreter,
  StdCtrls,Dialog_View,fs_ipascal, frxClass, frxDesgn,Class_Demo, OleCtrls,
  SIGNXLib_TLB,PerlRegEx, RzLine, RzButton, Menus, RzCmboBx;

type
  TForm1 = class(TDialogView)
    Btnx_1: TButton;
    fsScript1: TfsScript;
    Memo_1: TfsSyntaxMemo;
    RzSplitter1: TRzSplitter;
    frxReport1: TfrxReport;
    Btnx_2: TButton;
    Btnx_3: TButton;
    frxDesigner1: TfrxDesigner;
    SignX1: TSignX;
    Btnx_4: TButton;
    Btnx_5: TButton;
    Btnx_6: TButton;
    RzMenuButton1: TRzMenuButton;
    PopupMenu1: TPopupMenu;
    Menu_N11: TMenuItem;
    Menu_N21: TMenuItem;
    Menu_N31: TMenuItem;
    Comb_1: TRzComboBox;
    procedure Btnx_1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
    procedure Btnx_4Click(Sender: TObject);
    procedure Btnx_5Click(Sender: TObject);
    procedure Btnx_6Click(Sender: TObject);
    procedure RzMenuButton1Click(Sender: TObject);
    procedure Comb_1Change(Sender: TObject);
    procedure Comb_1CloseUp(Sender: TObject);
    procedure Comb_1SelEndOk(Sender: TObject);
  public
    FDemo:TDemo;

  protected
    procedure SetInitialize;override;
    procedure SetCommParams;override;
    procedure SetGridParams;override;
    procedure SetComboItems;override;
    procedure TryFreeAndNil;override;
  public
    function  GetPropEvent(Instance: TObject; ClassType: TClass;const PropName: String): Variant;
    function  TextToFloat(AValue:string):Extended;
    function  GetMultiply(AValue:Integer):Integer;
    function  CallMethod(Instance: TObject; ClassType: TClass;const MethodName: String; var Params: Variant): Variant;
  end;

var
  Form1: TForm1;

implementation

uses
  Class_KzUtils,Class_KzDebug,TypInfo;

{$R *.dfm}

procedure TForm1.Btnx_1Click(Sender: TObject);
var
  I:Integer;
  NumbA:Integer;
  PropList:PPropList;

  BoolA:Boolean;
begin
  FDemo:=TDemo.Create;
  FDemo.DemoIdex:='1';
  FDemo.DemoCode:='9527';
  FDemo.DemoName:='XXXX';
  FDemo.DemoMemo:='Demo';

  fsScript1.Clear;
  fsScript1.Lines.Text:=Memo_1.Lines.Text;

  with fsScript1.AddClass(TDemo,'TDemo') do
  begin
    {NumbA:=GetPropList(TDemo.ClassInfo,PropList);
    for I:=Low(PropList^) to NumbA-1 do
    begin
      AddProperty(PropList[I]^.Name,PropList[I]^.PropType^.Name,GetPropEvent,nil);
    end;}

    NumbA:=GetPropList(TDemo.ClassInfo,PropList);
    ShowMessageFmt('%D:%D:%D',[Low(proplist^),High(proplist^),NumbA]);
    for I:=Low(PropList^) to NumbA-1 do
    begin
      AddProperty(PropList[I]^.Name,'string',GetPropEvent,nil);
    end;
  end;

  fsScript1.AddMethod('function  GetMultiply(AValue:Integer):Integer',CallMethod);

  
  fsScript1.AddObject('param1',FDemo);
  fsScript1.Parent:=fsGlobalUnit;
  if fsScript1.Compile then
  begin
    fsScript1.CallFunction('ShowMsg','');
  end else
  begin
    ShowMessageFmt('%S',[fsScript1.ErrorMsg]);
  end;

  //PropList:=nil;
  FreeAndNil(FDemo);
  FreeMem(PropList);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
//
end;

procedure TForm1.SetComboItems;
begin
  inherited;

end;

procedure TForm1.SetCommParams;
begin
  inherited;
  RzSplitter1.Percent:=50;
end;

procedure TForm1.SetGridParams;
begin
  inherited;

end;

procedure TForm1.SetInitialize;
begin
  inherited;

end;

procedure TForm1.TryFreeAndNil;
begin
  inherited;

end;

procedure TForm1.Btnx_2Click(Sender: TObject);
begin
  frxReport1.ShowReport();
end;

procedure TForm1.Btnx_3Click(Sender: TObject);
begin
  frxReport1.DesignReport();
end;

function TForm1.GetPropEvent(Instance: TObject; ClassType: TClass;
  const PropName: String): Variant;
var
  I:Integer;
  NumbA:Integer;
  PropList:PPropList;
begin
  Result:=0;

  NumbA:=GetPropList(ClassType.ClassInfo,PropList);
  for I:=Low(PropList^) to NumbA-1 do
  begin
    if PropName=UpperCase(PropList[I]^.Name) then
    begin
      Result:=GetPropValue(Instance,PropList[I]^.Name);
    end;  
  end;
end;

procedure TForm1.Btnx_4Click(Sender: TObject);
var
  PerlA:TPerlRegEx;
  Source:string;
  ATag:string;
  DoubA:Extended;
begin
  Source:='hellow-lrldsdf';
  ATag  :='[^(\d+|\-|\.)]';
    
  try
    PerlA:=TPerlRegEx.Create;
    PerlA.Subject:=Source;
    PerlA.RegEx  :=ATag;
    PerlA.Replacement:='';

    PerlA.ReplaceAll;
    ShowMessage(PerlA.Subject);
    DoubA:=StrToFloat(PerlA.Subject);
    ShowMessageFmt('%F',[DoubA]);    
  finally
    FreeAndNil(PerlA);
  end;
end;

function TForm1.TextToFloat(AValue: string): Extended;
var
  PerlA:TPerlRegEx;
  Source:string;
  ATag:string;
  DoubA:Extended;
begin
  Result:=0;
  if (Trim(AValue)='') or (Trim(AValue)='-') then Exit;
  
  Source:=AValue;
  ATag  :='[^(\d+|\-|\.)]';
    
  try
    PerlA:=TPerlRegEx.Create;
    PerlA.Subject:=Source;
    PerlA.RegEx  :=ATag;
    PerlA.Replacement:='';

    PerlA.ReplaceAll;
    Result:=StrToFloatDef(PerlA.Subject,0);
  finally
    FreeAndNil(PerlA);
  end;
end;

procedure TForm1.Btnx_5Click(Sender: TObject);
var
  I:Integer;
  TextA:string;
  DoubA:Extended;
begin
  TextA:='sadfad4583.13';
  KzDebug.TickLog('1:1');
  for I:=0 to 10000 do
  begin
    DoubA:=TextToFloat(TextA);
  end;
  KzDebug.TickLog('1:2');    
end;

procedure TForm1.Btnx_6Click(Sender: TObject);
var
  I:Integer;
  TextA:string;
  DoubA:Extended;
begin
  TextA:='sadfad4583.13';
  KzDebug.TickLog('2:1');
  for I:=0 to 10000 do
  begin
    DoubA:=TKzUtils.TextToFloat(TextA);
  end;
  KzDebug.TickLog('2:2');    
end;

function TForm1.GetMultiply(AValue: Integer): Integer;
begin
  Result:=2 * AValue;
end;


function TForm1.CallMethod(Instance: TObject; ClassType: TClass;
  const MethodName: String; var Params: Variant): Variant;
begin
  Result:=GetMultiply(Params[0]);
end;

procedure TForm1.RzMenuButton1Click(Sender: TObject);
begin
  //
end;

procedure TForm1.Comb_1Change(Sender: TObject);
begin
  ShowMessage('comb_1change');
end;

procedure TForm1.Comb_1CloseUp(Sender: TObject);
begin
  ShowMessage('comb_1closeup');
end;

procedure TForm1.Comb_1SelEndOk(Sender: TObject);
begin
  ShowMessage('comb_1selend');
end;

end.
